import axios from "axios";
import admin from "../../../../01- 完成登陆/src/store/admin";

export default {
	state:{
		token:localStorage.getItem("token"),
		adminInfo:{}
	},
	mutations:{
		SET_TOKEN(state,token){
			state.token = token;
			localStorage.setItem("token",token);
		},
		SET_ADMIN_INFO(state,adminInfo){
			state.adminInfo = adminInfo;
		}
	},
	getters:{
		myAdmin(){
			return 200;
		}
	},
	actions:{
		// state,commit,dispatch
		async getAdminInfo({state,commit}){
			const {data} = await axios.get("/api/adminList/info",{
				headers:{
					token:state.token
				}
			});
			commit("SET_ADMIN_INFO",data.info);
		},
		// 登陆
		// content:
		//     state:当前模块下的数据状态
		//     rootState:顶级状态对象，通过该对象可以调用其它模块的数据状态以及顶级的数据状态。
		//     getters:当前模块下的getters对象
		//     rootGetters:顶级getters对象
		//     commit:调用其它的mutation函数
		//     dispatch:可以调用其它的action函数
		// payload：荷载的数据
		async login({commit},payload){
			// const {data} = axios.post("/admin/login",payload);
			const {data} = await axios.post("/api/admin/login",payload);
			commit("SET_TOKEN",data.token);
		}
	}
};